﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScoreMS.Model;

namespace ScoreMS.BLL
{
    /// <summary>
    /// 其他成绩，事务逻辑
    /// </summary>
    public class Score_otherBS
    {
        /// <summary>
        /// 获取单个其他成绩
        /// </summary>
        /// <returns></returns>
        static public Score_other GetScore_other(string course_id, string student_id)
        {
            using (scoremsdbEntities db = new scoremsdbEntities())
            {
                Score_other model = new Score_other();
                var score_other = db.score_other.FirstOrDefault(x => x.course_id == course_id && x.student_id == student_id);
                model.course_id = score_other.course_id;
                model.student_id = score_other.student_id;
                model.score_other_attendance = score_other.score_other_attendance;
                model.score_other_homework = score_other.score_other_homework;
                model.score_other_task = score_other.score_other_task;
                return model;
            }
        }

        /// <summary>
        /// 获取学生的其他成绩列表
        /// </summary>
        /// <param name="student_id"></param>
        /// <returns></returns>
        static public List<Score_other> GetScoreList(string student_id)
        {
            using (scoremsdbEntities db = new scoremsdbEntities())
            {
                var ret = db.score_other.Where(x => x.student_id == student_id);
                List<Score_other> list = new List<Score_other>();
                foreach (var score_other in ret)
                {
                    Score_other model = new Score_other();
                    model.course_id = score_other.course_id;
                    model.student_id = score_other.student_id;
                    model.score_other_attendance = score_other.score_other_attendance;
                    model.score_other_homework = score_other.score_other_homework;
                    model.score_other_task = score_other.score_other_task;
                    list.Add(model);
                }
                return list;
            }
        }

        /// <summary>
        /// 添加成绩
        /// </summary>
        /// <param name="model"></param>
        /// <returns>成功返回true</returns>
        static public bool AddScore(Score_other model)
        {
            try
            {
                using (scoremsdbEntities db = new scoremsdbEntities())
                {
                    db.score_other.AddObject(new score_other()
                    {
                        student_id = model.student_id,
                        course_id = model.course_id,
                        score_other_attendance = model.score_other_attendance,
                        score_other_homework = model.score_other_homework,
                        score_other_task = model.score_other_task
                    });
                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
